<?php
class news extends database{
	protected $_table = "tbl_news";
	public function getdata($id){
		$sql = "select * from $this->_table where news_id = '$id'";
		$this->query($sql);
		return $this->fetch();
	}
	public function listnews($start,$limit){
		$sql = "select * from $this->_table limit $start,$limit";
		$this->query($sql);
		return $this->fetchall();
	}
	public function add($title,$author,$info,$full,$date,$image=""){
		if($image != ""){
			$sql = "insert into $this->_table(news_title,news_author,news_info,news_full,news_date,news_image) values('$title','$author','$info','$full','$date','$image')";
		}else{
			$sql = "insert into $this->_table(news_title,news_author,news_info,news_full,news_date) values('$title','$author','$info','$full','$date')";
		}
		$this->query($sql);
	}
	public function edit($name,$pass,$fullname,$gender,$email,$phone,$level,$id){
		if($pass != NULL){ // có sửa password
			$sql = "update $this->_table set user_name='$name',user_pass='$pass',user_fullname='$fullname',user_gender='$gender',user_email='$email',user_phone='$phone',user_level='$level' where user_id = '$id'";
		}else{
			$sql = "update $this->_table set user_name='$name',user_fullname='$fullname',user_gender='$gender',user_email='$email',user_phone='$phone',user_level='$level' where user_id = '$id'";
		}
		$this->query($sql);
	}
	public function del($id){
		$sql = "delete from $this->_table where news_id = '$id'";
		$this->query($sql);
	}
	public function totalrecord(){
		$sql = "select * from $this->_table";
		$this->query($sql);
		return $this->num_rows();
	}
}